<?php
namespace Admin\Controller;
use Think\Controller;
class LogsController extends CommonController {
	// 添加页面
    public function index(){
    	//创建模板
    	$Logs = M('mvp_logs');
    	$User = M('mvp_user');

    	//获取关键字
        if(!empty($_GET['keywords'])){
            //建议使用数组形式来创建where条件
            // $where = "username like '%".$_GET['keyword']."%'";
            $where['lnumber'] = array('like','%'.$_GET["keywords"].'%');
            // $where['username'] = array('eq','admin');
            // $where['age'] = array('lt',18);
        }else{
            $where = "";
        }
        //获取总数
        $count = $Logs->where($where)->count();
        //获取每页显示的数量
        $num = !empty($_GET['num']) ? $_GET['num'] : 10;
        //实例化分页对象
        $page = new \Think\Page($count,$num);
        //获取limit参数
        $limit = $page->firstRow.','.$page->listRows;
        //获取页码信息(页码字符串)
        $pages = $page->show();

    	// $Logs = M('mvp_foods');
    	$linfo = $Logs->limit($limit)->where($where)->join('mvp_foods on mvp_logs.fid = mvp_foods.id')->field('mvp_foods.name,mvp_logs.*')->select();
    	// echo $Logs->_sql();
    	foreach ($linfo as $key => $value) {
    		$uinfo = $User->where($value['uid'] .'=id')->field('username')->select();
    		// var_dump($uinfo);
    		$linfo[$key]['uid']=$uinfo[0]['username'];
    	}

    	// var_dump($linfo);die;
    	$this->assign('linfo',$linfo);
    	$this->assign('pages',$pages);
        $this->display();

    }

      //删除操作
    public function delete(){
    	$id=I('get.id');
        // echo $id;die;
    	// echo $id;
    	$Logs = M('mvp_logs');
    	$num = $Logs->where('id='.$id)->delete();
    	// var_dump($num);
    	if($num == 1){
    		$this->success('删除成功',U('Admin/Logs/index'),3);
    	}else{
    		$this->error('删除失败',U('Admin/Logs/index'),3);

    	}

    }
  

}